package com.itcat.api;/*
 * @Author: gonhsl
 * @Date:2022-04-02-8:46
 * */

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itcat.api.mysql.OmsOrderReturnReasonApi;
import com.itcat.mapper.OmsOrderReturnReasonMapper;
import com.itcat.mysql.pojo.OmsOrderReturnReason;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@DubboService
public class OmsOrderReturnReasonApiImpl implements OmsOrderReturnReasonApi {
 @Autowired
 private OmsOrderReturnReasonMapper omsOrderReturnReasonMapper;
    @Override
    public Page<OmsOrderReturnReason> findList(Page<OmsOrderReturnReason> page) {
       return omsOrderReturnReasonMapper.selectPage(page,null);
    }

    @Override
    public void create(OmsOrderReturnReason returnReason) {
        omsOrderReturnReasonMapper.insert(returnReason);
    }

    @Override
    public void delete(List<Integer> ids) {
        omsOrderReturnReasonMapper.deleteBatchIds(ids);
    }

    @Override
    public void updateStatus(List<Integer> ids, Integer status) {
        LambdaUpdateWrapper<OmsOrderReturnReason> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.in(OmsOrderReturnReason::getId,ids).set(OmsOrderReturnReason::getStatus,status);
        OmsOrderReturnReason reason = new OmsOrderReturnReason();
        reason.setStatus(status);
        omsOrderReturnReasonMapper.update(reason,updateWrapper);
    }

    @Override
    public void update(OmsOrderReturnReason returnReason, Integer id) {
//        LambdaUpdateWrapper<OmsOrderReturnReason> updateWrapper = new LambdaUpdateWrapper<>();
//        updateWrapper.eq(OmsOrderReturnReason::getId,id).setEntity(returnReason);
//        omsOrderReturnReasonMapper.update(returnReason,updateWrapper);
        omsOrderReturnReasonMapper.updateById(returnReason);
    }

    @Override
    public OmsOrderReturnReason findOne(Integer id) {
        OmsOrderReturnReason omsOrderReturnReason = omsOrderReturnReasonMapper.selectById(id);
        return omsOrderReturnReason;
    }
}
